//
//  AppDelegate.m
//  ACE
//
//  Created by Mickey Yin on 2021/12/1.
//

#import "AppDelegate.h"
#import "AppDelegate+RootViewCtrl.h"
#import "AppDelegate+AppPush.h"
#import "AppDelegate+AppService.h"
#import "WXApi.h"

@interface AppDelegate ()<UIApplicationDelegate, WXApiDelegate>

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [self configRootView]; //配置window与根控制器相关
    
    [self configPush]; //配置推送业务相关
    
    [self configAppService];
    
    //在 register 之前打开 log , 后续可以根据 log 排查问题
    [WXApi startLogByLevel:WXLogLevelDetail logBlock:^(NSString *log) {
//        NSLog(@"WeChatSDK: %@", log);
    }];
    
    //向微信注册
    [WXApi registerApp:kwx_Appid universalLink:kwx_Universallink];
        
    //调用自检函数
    [WXApi checkUniversalLinkReady:^(WXULCheckStep step, WXCheckULStepResult* result) {
        NSLog(@"%@, %u, %@, %@", @(step), result.success, result.errorInfo, result.suggestion);
    }];
    
    return YES;
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return  [WXApi handleOpenURL:url delegate:self];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [WXApi handleOpenURL:url delegate:self];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * __nullable restorableObjects))restorationHandler {
    return [WXApi handleOpenUniversalLink:userActivity delegate:self];
}

@end
